import 'package:get/get.dart';

import '../../../constants.dart';
import '../../../models/case_list_entity.dart';
import '../../../routes/app_routes.dart';
import '../../../services/api_service.dart';
import '../../../services/common_service.dart';
import '../seal_create/logic.dart';

class SealSelectCaseLogic extends GetxController {
  final apiService = Get.find<ApiService>();
  final commonService = Get.find<CommonService>();

  final sealPaperType = Rxn<SealPaperType>();

  var isReloadList = true.obs;
  var caseList = <CaseInfo>[].obs;

  @override
  void onInit() {
    super.onInit();
    sealPaperType.value = Get.arguments;

    _getCaseList();
  }

  void selectCase(int index) {
    Get.toNamed(RouteGet.sealCreate,
        arguments: SealCreateParams(
          sealPaperType: sealPaperType.value!,
          caseId: caseList[index].id,
          caseName: caseList[index].caseNameStr,
        ));
  }

  void _getCaseList() {
    apiService.listAllCase(commonService.getRole()).then((caseList) => {
          isReloadList.value = false,
          if (caseList != null) {this.caseList.addAll(caseList.all!)}
        });
  }
}
